const { http, handleStar } = require("../../utils/http3000")
Page({
  data: {
    currentCity: "",
    banner: [],
    autoplay: true,
    interval: 3000,
    duration: 1200,
  },
  onLoad() {
    var url = `http://47.108.197.28:4000/api/banner`
    http({
      url,
      success: res => {
        var banner = res.data.res
        this.setData({
          banner
        })
      }
    })
    var top = `http://47.108.197.28:4000/api/movie/comingSoon`
    http({
      url: top,
      success: res => {
        var movie = []
        console.log(res)
        var res = res.data.res
        res.splice(0,3).forEach(item => {
          var { title, pic, rating, _id } = item;
          var star = rating
          console.log(item.rating)
          movie.push({
            title,
            pic,
            rating,
            _id,
            star: handleStar(star)
          })
        })
        this.setData({
          movie
        })
      }
    })
    var inTheaters = `http://47.108.197.28:4000/api/movie/inTheaters`
    http({
      url: inTheaters,
      success: res => {
        var Theaters = []
        console.log(res)
        var res = res.data.res
        res.splice(0,3).forEach(item => {
          var { title, pic, raiting, _id } = item;
          var star = raiting
          console.log(item.rating)
          Theaters.push({
            title,
            pic,
            raiting,
            _id,
            star: handleStar(star)
          })
        })
        this.setData({
          Theaters
        })
      }
    })
  }
})